package com.seckill.rabbitmq;

import com.alibaba.fastjson.JSON;
import com.seckill.redis.RedisService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author yangjunwei
 * @date 2021/11/11 11:22 上午
 */
@Service
public class MQSender {

    private Logger log = LoggerFactory.getLogger(MQSender.class);

    @Autowired
    AmqpTemplate amqpTemplate;

    public void sendMiaoshaMsg(MiaoshaMessage miaoshaMessage) {
        log.info("sendMiaoshaMsg ============> {}", JSON.toJSONString(miaoshaMessage));
        amqpTemplate.convertAndSend(MQConfig.MIAOSHA_QUEUE, JSON.toJSONString(miaoshaMessage));
    }

//    public void sendMiaoshaOrder(Integer orderId){
//        log.info("delay order ======================> {}",orderId);
//        amqpTemplate.convertAndSend(MQConfig.MIAOSHA_ORDER_QUEUE,JSON.toJSONString(orderId)
//        ,new S);
//    }

//    public void send(Object message) {
//        String msg = RedisService.beanToString(message);
//        log.info("send msg :{}", msg);
//        amqpTemplate.convertAndSend(MQConfig.QUEUE, msg);
//    }
//
//    public void sendTopic(Object message) {
//        String msg = RedisService.beanToString(message);
//        log.info("send topic message:" + msg);
//        amqpTemplate.convertAndSend(MQConfig.TOPIC_EXCHANGE, "topic.key1", msg + "1");
//        amqpTemplate.convertAndSend(MQConfig.TOPIC_EXCHANGE, "topic.key2", msg + "2");
//    }
//
//    public void fanoutSend(Object message) {
//        String msg = RedisService.beanToString(message);
//        log.info("fanoutSend message:" + msg);
//        amqpTemplate.convertAndSend(MQConfig.FANOUT_EXCHANGE, "", msg);
//    }
//
//    public void sendHeader(Object message) {
//        String msg = RedisService.beanToString(message);
//        log.info("send header msg:{}", msg);
//        MessageProperties properties = new MessageProperties();
//        properties.setHeader("header1", "value1");
//        properties.setHeader("header2", "value2");
//        Message obj = new Message(msg.getBytes(), properties);
//        amqpTemplate.convertAndSend(MQConfig.HEADERS_EXCHANGE, "", obj);
//    }


}
